import Vue from 'vue'
import App from './App.vue'
import router from './router'
import './style/index.css'
import axios from 'axios' //导入axios
import dayjs from 'dayjs' // 安装dayjs
import treeTable from 'vue-table-with-tree-grid' // 安装dayjs
import NProgress from 'nprogress'

// import ElementUI from 'element-ui';
// Vue.use(ElementUI);


Vue.config.productionTip = false

const baseURL = process.env.NODE_ENV === 'production' ? "http://122.51.249.55:5000/api/private/v1/" : "http://127.0.0.1:8888/api/private/v1/"
axios.defaults.baseURL = baseURL
axios.interceptors.request.use(function(config) {
    // 启用进度条
    NProgress.start()
        //在请求发出之前进行一些信息设置
    config.headers.Authorization = sessionStorage.getItem('userinfo') ? JSON.parse(sessionStorage.getItem('userinfo')).token : ''
    return config;
}, function(err) {
    // 处理响应的错误信息
    return Promise.reject(err)
});

axios.interceptors.response.use(response => {
    // 停止进度条
    NProgress.done()
    return response
}, error => {
    return Promise.reject(error)
})




// 注册树状表格组件
Vue.component('tree-table', treeTable)
    // 挂载axios方法
Vue.prototype.$axios = axios
    // 注册全局过滤器
Vue.filter('dataFormate', (val, str = "YYYY-MM-DD HH:MM:ss") => {
    return dayjs(val * 1000).format(str)
})
Vue.prototype.$baseURL = baseURL

new Vue({
    router,
    render: h => h(App)
}).$mount('#app')